'use strict';

/* Controllers */
app.controller('SigninFormController', ['$scope', '$http', '$state', 'apiService','$cookieStore','$timeout', function ($scope, $http, $state, apiService,$cookieStore,$timeout) {
  $scope.user = {};
  $scope.authError = null;
  $cookieStore.remove('cy__member');

  $scope.login = function () {
    $scope.authError = null;
    $scope.btn_disabled = true;
    // 提交数据
    apiService.post({
      modelName: 'member',
      apiName: 'loginMember'
    }, {
      username: $scope.user.name,
      password: $scope.user.password
    }, function (data) {
      $scope.btn_disabled = false;
      if (data.code == 200) {
        $cookieStore.put('cy__member',data['memberdb']);
        $scope.authError = '登陆成功！';
        $timeout(function(){
          $state.go('app.dashboard-v1');
        },300);
      } else {
        $scope.authError = data['msc'];
      }
    }, function (err) {
      $scope.btn_disabled = false;
      console.log(err);
      $scope.authError = '服务器出小差咯！';
    });

  };
}]);